/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1World;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.packetserver.S_ServerMessage;

/**
 * Class <code>MagicScrollBuff</code> 选择目标 - 远距离. <br>
 * 40859 - 魔法卷轴 (初级治愈术) <br>
 * 40866 - 魔法卷轴 (神圣武器) <br>
 * 40867 - 魔法卷轴 (解毒术) <br>
 * 40877 - 魔法卷轴 (中级治愈术) <br>
 * 40884 - 魔法卷轴 (通畅气脉术) <br>
 * 40893 - 魔法卷轴 (高级治愈术) <br>
 * 40895 - 魔法卷轴 (圣洁之光) <br>
 * 49281 - 魔法卷轴 (体魄强健术) <br>
 * 49282 - 魔法卷轴 (祝福魔法武器) <br>
 * 49286 - 魔法卷轴 (全部治愈术) <br>
 * 
 * @author jrwz
 * @version 2012-6-19下午04:03:46
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class MagicScrollBuff extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new MagicScrollBuff();
    }

    /** 选择目标 - 远距离. */
    private MagicScrollBuff() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        final int targetID = targetId;

        if (targetID == 0) {
            pc.sendPackets(new S_ServerMessage(281)); // \f1施咒取消。
            return;
        }

        final L1Object target = L1World.getInstance().findObject(targetID);

        final int spellsc_x = target.getX();
        final int spellsc_y = target.getY();
        final int useCount = 1;

        if (pc.getInventory().removeItem(useItem, useCount) >= useCount) {
            final int itemId = useItem.getItemId();
            int skillid = itemId - 40858;

            switch (itemId) {
                case 49281: // 魔法卷轴 (体魄强健术)
                    skillid = 42;
                    break;

                case 49282: // 魔法卷轴 (祝福魔法武器)
                    skillid = 48;
                    break;

                case 49286: // 魔法卷轴 (全部治愈术)
                    skillid = 57;
                    break;
            }

            final L1SkillUse l1skilluse = new L1SkillUse();
            l1skilluse.handleCommands(pc, skillid, targetID, spellsc_x,
                    spellsc_y, null, 0, L1SkillUse.TYPE_SPELLSC);
        }
    }
}
